package com.newtouch.bxzs.database.synchronize.batch.steplistener;

import com.newtouch.bxzs.database.synchronize.mapper.CustomerMapper;
import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.StepListener;
import org.springframework.batch.core.annotation.AfterStep;
import org.springframework.batch.core.annotation.BeforeStep;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 客户同步任务监听
 *
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2020/12/31 13:25</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author yuanjie
 * @version 1.0.0
 * @since 1.0.0
 */
@Component
public class CustomerStepListener implements StepListener {

    @Autowired
    private CustomerMapper customerMapper;

    @BeforeStep
    public void beforeStep(StepExecution stepExecution) {
        customerMapper.dropTable();
        customerMapper.createTable();
        System.out.println("客户同步开始"+stepExecution.getStartTime());
    }

    @AfterStep
    public ExitStatus afterStep(StepExecution stepExecution) {
        System.out.println("客户同步结束"+stepExecution.getLastUpdated());
        customerMapper.dropTable();
        return ExitStatus.COMPLETED;
    }
}
